require(['./config'], () => {
    require(['header', 'footer'], () => {
        class Register {
            constructor() {
                this.register()
            }
            register() {
                $("#register").on('click', function () {
                    var username = $('#username').val(),
                        password = $('#password').val()

                    var userlist = localStorage.getItem('userlist')
                    if (username && password) {
                        if (userlist) {
                            userlist = JSON.parse(userlist)
                            userlist.push({ username, password })
                            localStorage.setItem('userlist', JSON.stringify(userlist))
                        } else {
                            let userinfo = { username, password }
                            var arr = [userinfo]
                            localStorage.setItem('userlist', JSON.stringify(arr))
                        }
                        alert("注册成功，即将跳转到登录页面!")
                        window.open('./login.html')
                    } else {
                        alert("输入格式错误，请重试!")
                    }
                })
            }
        }
        return new Register()
    })
})